import command.*;
import entity.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class CommandContorller {

    private static final Command[] commands = {new CreateCommand(),new UpdateCommand(),new DeleteCommand(),new ListCommand()};

    private static final Stack<Command> stack = new Stack<>();
    public static void execute(int choice, List<Student> students) throws Exception {
        if(choice == 5){
            undo(students);
            return;
        }

        Command command = commands[choice - 1];
        command.execute(students);
        stack.push(command);
    }

    public static void undo(List<Student> students) {
        if(stack.empty()){
            System.err.println("没有可撤销的操作！");
            return;
        }

        Command command = stack.pop();
        command.undo(students);
    }
}
